<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>转换为String</title>
</head>
<body>
<script type="text/javascript">
  var a = 123;
  a =a.toString();

  console.log(a);
  console.log(typeof  a);

  a = null;
  // a = a.toString();//Uncaught TypeError
  console.log(a);
  console.log(typeof  a);

  a = undefined;
  // a = a.toString();//Uncaught TypeError
  console.log(a);
  console.log(typeof  a);

  a = null;
  a = String(a)
  console.log(a);//null
  console.log(typeof  a);//string

  a = undefined;
  a = String(a);
  console.log(a);//undefined
  console.log(typeof  a);//string
</script>
</body>
</html>